﻿Imports EVOLTA.Promocion.Bl.Bc
Imports EVOLTA.Promocion.Bl.Be

Partial Class reportes_reporteProforma
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.CacheControl = "no-cache"
        Response.AddHeader("Pragma", "no-cache")
        Response.Expires = -1
        '***********************************************************'
        If Not IsPostBack Then
            'Me.sPosibleCliente = Nothing
            'Me.sCliente = Nothing
        End If
    End Sub
    Protected Sub btnConsultar_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        '-------   PROFORMA   --------------'        
        Dim proformaDetalle As New EproformaDetalle
        With proformaDetalle
            .idProyecto = Me.Master.idProyecto
            .idEtapa = Me.Master.idEtapa
        End With
        proforma(proformaDetalle, txtBuscar.Value)
        '-----------------------------------'

        '-------   SEPARACIO VENTA   -------'        
        Dim separacionVenta As New EseparacionVentaDetalle
        With separacionVenta
            .idProyecto = Me.Master.idProyecto
            .idEtapa = Me.Master.idEtapa
        End With
        separacion(separacionVenta, txtBuscar.Value)
        ventas(separacionVenta, txtBuscar.Value)
        '-----------------------------------'


        Me.lblPrecioTotalInmueble.Text = (CType(lblTotalPrecioxInmbProforma.Text, Decimal) + _
                                          CType(lblTotalPrecioInmbSeparacion.Text, Decimal) + _
                                          CType(lblTotalPrecioxInmbVenta.Text, Decimal)).ToString("###,###,##0.00")

        Me.lblPrecioTotalComision.Text = (CType(lblTotalComisionProforma.Text, Decimal) + _
                                          CType(lblTotalComisionSeparacion.Text, Decimal) + _
                                          CType(lblTotalComisionVenta.Text, Decimal)).ToString("###,###,##0.00")
        upMonto.Update()
        upTotal.Update()
    End Sub
    Private Sub proforma(ByVal proformaDetalle As EproformaDetalle, ByVal filtro As String)
        Dim Lproformadetalle As New List(Of EproformaDetalle)
        Lproformadetalle = RproformaDetalle.selecionar_selXVendedorComision(Me.Master.descEmpresa, proformaDetalle, filtro)
        If Not Lproformadetalle Is Nothing Then
            gvwVendedorProforma.DataSource = Lproformadetalle
            gvwVendedorProforma.DataBind()
            upProforma.Update()
        End If

        Dim totalValorVenta As Decimal = 0
        Dim totalComision As Decimal = 0
        For Each p As EproformaDetalle In Lproformadetalle
            totalValorVenta += p.valorVenta
            totalComision += p.comisionProforma
        Next

        Me.lblTotalPrecioxInmbProforma.Text = totalValorVenta.ToString("###,###,##0.00")
        Me.lblTotalComisionProforma.Text = totalComision.ToString("###,###,##0.00")
        upMontoProforma.Update()
        upTotalProforma.Update()
    End Sub
    Private Sub separacion(ByVal separacionDetalle As EseparacionVentaDetalle, ByVal filtro As String)
        Dim LseparacionDetalle As New List(Of EseparacionVentaDetalle)
        LseparacionDetalle = RseparacionVentaDetalle.seleccionar_selXVendedorComisionSeparacion(Me.Master.descEmpresa, separacionDetalle, filtro)
        If Not LseparacionDetalle Is Nothing Then
            gvwVendedorSeparacion.DataSource = LseparacionDetalle
            gvwVendedorSeparacion.DataBind()
            upSeparacion.Update()
        End If

        Dim totalValorVenta As Decimal = 0
        Dim totalComision As Decimal = 0
        For Each p As EseparacionVentaDetalle In LseparacionDetalle
            totalValorVenta += p.valorVenta
            totalComision += p.comisionSeparacionVenta
        Next

        Me.lblTotalPrecioInmbSeparacion.Text = totalValorVenta.ToString("###,###,##0.00")
        Me.lblTotalComisionSeparacion.Text = totalComision.ToString("###,###,##0.00")
        upMontoSeparacion.Update()
        upTotalSeparacion.Update()
    End Sub
    Private Sub ventas(ByVal separacionDetalle As EseparacionVentaDetalle, ByVal filtro As String)
        Dim LseparacionDetalle As New List(Of EseparacionVentaDetalle)
        LseparacionDetalle = RseparacionVentaDetalle.seleccionar_selXVendedorComisionVentas(Me.Master.descEmpresa, separacionDetalle, filtro)
        If Not LseparacionDetalle Is Nothing Then
            gvwVendedorVenta.DataSource = LseparacionDetalle
            gvwVendedorVenta.DataBind()
            upVenta.Update()
        End If

        Dim totalValorVenta As Decimal = 0
        Dim totalComision As Decimal = 0
        For Each p As EseparacionVentaDetalle In LseparacionDetalle
            totalValorVenta += p.valorVenta
            totalComision += p.comisionSeparacionVenta
        Next

        Me.lblTotalPrecioxInmbVenta.Text = totalValorVenta.ToString("###,###,##0.00")
        Me.lblTotalComisionVenta.Text = totalComision.ToString("###,###,##0.00")
        upMontoVenta.Update()
        upTotalVenta.Update()
    End Sub
    Protected Sub gvwVendedorProforma_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
        Handles gvwVendedorProforma.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add("OnMouseOver", "Resaltar_On(this);")
            e.Row.Attributes.Add("OnMouseOut", "Resaltar_Off(this);")
            e.Row.Attributes("OnClick") = Page.ClientScript.GetPostBackClientHyperlink(Me.gvwVendedorProforma, "Select$" + e.Row.RowIndex.ToString)
            e.Row.Style.Add("cursor", "hand")
        End If
    End Sub
    Protected Sub gvwVendedorSeparacion_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
        Handles gvwVendedorSeparacion.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add("OnMouseOver", "Resaltar_On(this);")
            e.Row.Attributes.Add("OnMouseOut", "Resaltar_Off(this);")
            e.Row.Attributes("OnClick") = Page.ClientScript.GetPostBackClientHyperlink(Me.gvwVendedorSeparacion, "Select$" + e.Row.RowIndex.ToString)
            e.Row.Style.Add("cursor", "hand")
        End If
    End Sub
    Protected Sub gvwVendedorVenta_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
        Handles gvwVendedorVenta.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add("OnMouseOver", "Resaltar_On(this);")
            e.Row.Attributes.Add("OnMouseOut", "Resaltar_Off(this);")
            e.Row.Attributes("OnClick") = Page.ClientScript.GetPostBackClientHyperlink(Me.gvwVendedorVenta, "Select$" + e.Row.RowIndex.ToString)
            e.Row.Style.Add("cursor", "hand")
        End If
    End Sub
    Protected Sub btnCancelar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        txtBuscar.Value = ""
        Me.gvwVendedorProforma.DataSource = Nothing
        Me.gvwVendedorProforma.DataBind()
        upProforma.Update()

        Me.gvwVendedorSeparacion.DataSource = Nothing
        Me.gvwVendedorSeparacion.DataBind()
        upSeparacion.Update()

        Me.gvwVendedorVenta.DataSource = Nothing
        Me.gvwVendedorVenta.DataBind()
        upVenta.Update()

        txtBuscar.Focus()
    End Sub

End Class
